package com.sunny.sudy.mq.listener;

import cn.hutool.core.date.DateUtil;
import com.sunny.sudy.mq.entity.SysConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @ClassName: ReceiveMsgListener
 * @Description: 接收消息监听类
 * @Author: sunt
 * @Date: 2020/5/23 9:26
 * @Version 1.0
 **/
@Component
@EnableRabbit
@Slf4j
public class ReceiveMsgListener {

    /**
     * 监听队列的消息
     * @RabbitListener(queues = SysConstant.QUEUE_TEST_HELLO) 代表监听的队列名称
     * @param msg 消息内容
     */
    @RabbitListener(queues = SysConstant.QUEUE_TEST_HELLO)
    @RabbitHandler
    public void getTestMsg(String msg) {
        log.info("---------->接收到的消息:{}",msg);
    }

    /**
     * 获取到的延时消息
     * 这里接收到消息进行对应的业务处理(例如:取消订单，关闭支付，回滚库存等 ...)
     * @param msg
     */
    @RabbitListener(queues = SysConstant.SYS_ORDER_RECEIVE_QUEUE)
    @RabbitHandler
    public void getdelayMsg(String msg) {
        log.info("MQ接收消息时间:{},消息内容:{}", DateUtil.formatDateTime(DateUtil.date()),msg);
        log.info("------->这里实现订单关闭、支付关闭、回滚库存业务逻辑...");
    }
}
